﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace ScheduleMaker
{
    public partial class smSubjectAndGroups : Form
    {
        IList<DB.Domain.Core.Subject> subjects;
        IList<DB.Domain.Core.Group> groups;
        public smSubjectAndGroups()
        {
            InitializeComponent();
            grid.Rows.Clear();
            grid.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            grid.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            loadGroups();
            loadSubjects();
        }

        private void loadSubjects()
        {
            // Wczytanie dni tygodnia.
            /*
            DB.SubjectDAOSchool sDao = new SubjectDAOSchool();
            subjects = sDao.getAll();

            grid.ColumnCount = subjects.Count + 1;
            grid.Columns[0].Name = "Przedmiot \\\n Grupa";
            grid.Columns[0].Frozen = true;
            int i = 1;
            foreach (var subject in subjects)
            {
                grid.Columns[i].Name = subject.Name;
                i++;
            }*/
            DB.CoreDAO.SubjectDAO sDAO = DB.DAOFactory.getSubjectDAO(ConfigManager.ConfigManager.getConfiguration().Type);
            subjects = sDAO.getAll();
            foreach (var subject in subjects)
            {
                int row = grid.Rows.Add();
                grid.Rows[row].Cells[0].Value = subject.Name;
                grid.Rows[row].Height = 30;
                for (int column = 1; column < grid.ColumnCount; column++)
                {
                    foreach (var group in groups)
                    {
                        if (grid.Columns[column].Name.Equals(group.Name))
                        {
                            IDictionary<DB.Domain.Core.Subject, int> groupSubjects = group.SubjectsCount;
                            if (groupSubjects.Keys.Contains(subject))
                            {
                                grid.Rows[row].Cells[column].Value = groupSubjects[subject];
                            }
                        }
                    }
                }
            }
        }
        private void loadGroups()
        {
            //Wczytywanie Grup
            /*
            DB.GroupDAOSchool gDAO = new GroupDAOSchool();
            groups = gDAO.getAll();

            int i = 0;
            foreach (var group in groups)
            {
                int row = grid.Rows.Add();
                grid.Rows[row].Cells[0].Value = group.Name;
                IDictionary<DB.Domain.SubjectSchool, int> groupSubjects = group.SubjectsCount;
                foreach (var subject in groupSubjects.Keys) {
                    for (int column = 1; column < grid.Columns.Count; column++ )
                    {
                        if (grid.Columns[column].Name.Equals(subject.Name))
                        {
                            grid.Rows[row].Cells[column].Value = groupSubjects[subject];
                        }
                    }
                }
            }*/
            DB.CoreDAO.GroupDAO gDao = DB.DAOFactory.getGroupDAO(ConfigManager.ConfigManager.getConfiguration().Type); ;
            groups = gDao.getAll();
            grid.ColumnCount = groups.Count + 1;
            grid.Columns[0].Frozen = true;
            int i = 1;
            foreach (var group in groups)
            {
                grid.Columns[i].Name = group.Name;
                i++;
            }
        }
    }
}
